package org.orange.springboot.simulate.springboots.test.service.impl;


import org.orange.springboot.simulate.springboots.test.service.OrderService;
import org.orange.springboot.simulate.springboots.test.service.UserService;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("userService")
//@Scope("prototype") //多例
//BeanNameAware回调接口，把某个Bean的名字告诉程序员
public class UserServiceImpl implements UserService, BeanNameAware, InitializingBean {

    @Autowired
    private OrderService orderService;

    private String beanName;    //Bean实例的名字，通过BeanNameAware的setter方法赋值

    @Override
    public void test() {
        System.out.println(orderService);
        orderService.submitOrder();
    }

    @Override
    public void sayHello() {
        System.out.println("hello user");
        orderService.delOrder();
    }

    @Override
    public void setBeanName(String beanName) {
        this.beanName = "userService";
    }

    @Override
    public void afterPropertiesSet() {
        System.out.println("初始化方法");
    }
}
